package com.firmye.codereposboot.service;

import com.firmye.codereposboot.dao.OrdersDao;
import com.firmye.codereposboot.dao.OrdersProductDao;
import com.firmye.codereposboot.model.orders.pojo.Orders;
import com.firmye.codereposboot.model.orders.pojo.OrdersProduct;
import com.firmye.codereposboot.utils.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;

@Slf4j
@Service
public class OrdersService {

    @Autowired
    private OrdersDao ordersDao;
    @Autowired
    private OrdersProductDao ordersProductDao;

    public boolean batchCreate() throws ParseException {
        for (int i = 0;i < 30000;i++){
            Orders orders = new Orders();
            orders.setCreatedTime(RandomUtil.getRandomDate("2018-01-01 00:00:00","2019-12-31 23:59:59"));
            ordersDao.insert(orders);

            OrdersProduct ordersProduct = new OrdersProduct();
            ordersProduct.setOrderId(orders.getOrderId());
            ordersProduct.setProId(RandomUtil.getInteger(1,11));
            ordersProduct.setProNum(RandomUtil.getInteger(1,10));
            ordersProductDao.insert(ordersProduct);
        }

        return true;
    }

}
